home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / dev / lang / SmallEiffel.lha / SmallEiffel / sys / runtime / no_check.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-12-22  |  7.8 KB  |  358 lines

  1. /*
  2. -- This file is  free  software, which  comes  along  with  SmallEiffel. This
  3. -- software  is  distributed  in the hope that it will be useful, but WITHOUT 
  4. -- ANY  WARRANTY;  without  even  the  implied warranty of MERCHANTABILITY or
  5. -- FITNESS  FOR A PARTICULAR PURPOSE. You can modify it as you want, provided
  6. -- this header is kept unaltered, and a notification of the changes is added.
  7. -- You  are  allowed  to  redistribute  it and sell it, alone or as a part of 
  8. -- another product.
  9. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  10. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr 
  11. --                       http://www.loria.fr/SmallEiffel
  12. --
  13. */
  14.  
  15. /*
  16.   This file (no_check.c) is automatically included when `run_control.no_check'
  17.   is true (ie. all modes ecxept -boost).
  18. */
  19.  
  20. /*
  21.   The upper most context (SmallEiffel Dump stack Top) :
  22. */
  23. se_dump_stack* se_dst=NULL;
  24.  
  25. void se_print_run_time_stack(void) {
  26.   /* GENERAL.print_run_time_stack */
  27.   se_dump_stack* ds = NULL;
  28.   se_dump_stack* ds2;
  29.   se_frame_descriptor* fd;
  30.   int frame_count = 1;
  31.  
  32.   ds = se_dst;
  33.   if (ds == NULL) {
  34.     fprintf(SE_ERR,"Empty stack.\n");
  35.     return ;
  36.   }
  37.   else {
  38.     while (ds->caller != NULL) {
  39.       ds = ds->caller;
  40.       frame_count++;
  41.     }
  42.   }
  43.   fprintf(SE_ERR,"%d frames in current stack.\n",frame_count);
  44.   fprintf(SE_ERR,"=====  Bottom of run-time stack  =====\n");
  45.   while (ds != NULL) {
  46.     if (ds->fd != NULL) {
  47.       se_print_one_frame(ds);
  48.     }
  49.     else {
  50.       fprintf(SE_ERR,"External CECIL call.\n");
  51.     }
  52.     /* Next frame : */
  53.     if (ds == se_dst) {
  54.       ds = NULL;
  55.     }
  56.     else {
  57.       ds2 = se_dst;
  58.       while (ds2->caller != ds) {
  59.     ds2 = ds2->caller;
  60.       }
  61.       ds = ds2;
  62.     }
  63.     if (--frame_count) {
  64.       fprintf(SE_ERR,"======================================\n");
  65.     }
  66.   }
  67.   fprintf(SE_ERR,"=====   Top of run-time stack    =====\n");
  68. }
  69.  
  70. void se_print_one_frame(se_dump_stack* ds) {
  71.   se_frame_descriptor* fd = ds->fd;
  72.   int i = 0;
  73.   int local_count = 0;
  74.   char* local_format = fd->local_format;
  75.   int expanded;
  76.   int id;
  77.   void** var;
  78.   fprintf(SE_ERR,"%s\n",fd->name);
  79.   if (fd->use_current) {
  80.     fprintf(SE_ERR,"Current = ");
  81.     i = 2;
  82.     id = 0;
  83.     while (local_format[i] != '%') {
  84.       id = (id * 10) + (local_format[i] - '0');
  85.       i++;
  86.     }
  87.     i++;
  88.     (se_prinT[id])(ds->current);
  89.     fprintf(SE_ERR,"\n");
  90.   }
  91.   while (local_count < fd->local_count) {
  92.     while (local_format[i] != '%') {
  93.       fprintf(SE_ERR,"%c",local_format[i]);
  94.       i++;
  95.     }
  96.     i++;
  97.     expanded = ((local_format[i++] == 'E')?1:0);
  98.     fprintf(SE_ERR," = ");
  99.     id = 0;
  100.     while (local_format[i] != '%') {
  101.       id = (id * 10) + (local_format[i] - '0');
  102.       i++;
  103.     }
  104.     i++;
  105.     var = (ds->locals)[local_count];
  106.     if (expanded) {
  107.       (se_prinT[id])((void**)(var));
  108.     }
  109.     else if (*var == NULL) {
  110.       fprintf(SE_ERR,"Void");
  111.     }
  112.     else {
  113.       (se_prinT[((T0*)(*var))->id])((void**)(var));
  114.     }
  115.     fprintf(SE_ERR,"\n");
  116.     local_count++;
  117.   }
  118.   fprintf(SE_ERR,"line %d ",ds->l);
  119.   fflush(SE_ERR);
  120.   fprintf(SE_ERR,"column %d ",ds->c);
  121.   fflush(SE_ERR);
  122.   fprintf(SE_ERR,"file %s \n",p[ds->f]);
  123.   fflush(SE_ERR);
  124. }
  125.  
  126. void se_core_dump(char*msg) {
  127.   if (msg != NULL) {
  128.     fprintf(SE_ERR,"%s\n",msg);
  129.   }
  130. #ifdef SE_EXCEPTIONS
  131.   print_exception();
  132. #endif
  133.   se_print_run_time_stack();
  134.   exit(1);
  135. }
  136.  
  137. int se_require_uppermost_flag;
  138.  
  139. /*
  140.   Require Last Result :
  141. */
  142. int se_require_last_result;
  143.  
  144. int se_rci(void*C) {
  145.   /* Return 1 if class invariant must be checked for Current 
  146.      before leaving the routine.
  147.   */
  148.   se_dump_stack*ds = se_dst;
  149.   ds = ds->caller;
  150.   if (ds != NULL) {
  151.     se_frame_descriptor* fd = ds->fd;
  152.     if (fd == NULL) {
  153.       /* As for example when coming via CECIL. */
  154.       return 0;
  155.     }
  156.     else {
  157.       if (fd->use_current) {
  158.     if (fd->local_format[1] == 'R') {
  159.       if (((void*)*(ds->current)) == C) {
  160.         return 0;
  161.       }
  162.     }
  163.       }
  164.     }
  165.   }
  166.   return 1;
  167. }
  168.  
  169. void error0(char*m) {
  170.   static char*f1="*** Error at Run Time *** : %s\n";
  171.   fprintf(SE_ERR,f1,m);
  172. #ifdef SE_EXCEPTIONS
  173.   print_exception();
  174. #endif
  175.   se_print_run_time_stack();
  176.   fprintf(SE_ERR,f1,m);
  177.   exit(1);
  178. }
  179.  
  180. void error1(char*m,int l,int c,int f) {
  181.   char*f1="Line : %d column %d in %s.\n";
  182.   char*f2="*** Error at Run Time *** : %s\n";
  183.   fprintf(SE_ERR,f1,l,c,p[f]);
  184.   fprintf(SE_ERR,f2,m);
  185. #ifdef SE_EXCEPTIONS
  186.   print_exception();
  187. #endif
  188.   se_print_run_time_stack();
  189.   fprintf(SE_ERR,f1,l,c,p[f]);
  190.   fprintf(SE_ERR,f2,m);
  191.   exit(1);
  192. }
  193.  
  194. void error2(T0*o,int l,int c,int f) {
  195.   char*f1="Target Type %s not legal.\n";
  196.   fprintf(SE_ERR,f1,s2e(t[o->id]));
  197.   error1("Bad target.",l,c,f);
  198. }
  199.  
  200. T0* vc(void*o,int l,int c,int f) {
  201.   /* VoidCheck for reference target.*/
  202.   if (o != NULL) {
  203.     return o;
  204.   }
  205.   else {
  206. #ifdef SE_EXCEPTIONS
  207.     internal_exception_handler(Void_call_target);
  208. #else
  209.     error1("Call with a Void target.",l,c,f);
  210. #endif
  211.     return NULL;
  212.   }
  213. }
  214.  
  215. T0* ci(int id,void*o,int l,int c,int f) {
  216.   /* Check Id for reference target. */
  217.   vc(o,l,c,f);
  218.   if (id == (((T0*)o)->id)) {
  219.     return o;
  220.   }
  221.   else {
  222. #ifdef SE_EXCEPTIONS
  223.     internal_exception_handler(Routine_failure);
  224. #else
  225.     fprintf(SE_ERR,"Line : %d column %d in %s.\n",l,c,p[f]);
  226.     fprintf(SE_ERR,"*** Error at Run Time *** : ");
  227.     fprintf(SE_ERR,"Target is not valid (not the good type).\n");
  228.     fprintf(SE_ERR,"Expected: %s, Actual: %s.\n",
  229.         s2e(t[id]),s2e(t[((T0*)o)->id]));
  230.     se_print_run_time_stack();
  231.     exit(1);
  232. #endif
  233.   }
  234. }
  235.  
  236. void ac_req(int v) {
  237.   if (!v && se_require_uppermost_flag) {
  238. #ifdef SE_EXCEPTIONS
  239.     internal_exception_handler(Precondition);
  240. #else
  241.     error0("Require Assertion Violated.");
  242. #endif
  243.   }
  244.   se_require_last_result=se_require_last_result&&v;
  245. }
  246.  
  247. void ac_ens(int v) {
  248.   if (!v) {
  249. #ifdef SE_EXCEPTIONS
  250.     internal_exception_handler(Postcondition);
  251. #else
  252.     error0("Ensure Assertion Violated.");
  253. #endif
  254.   }
  255. }
  256.  
  257. void ac_inv(int v) {
  258.   if (!v) {
  259. #ifdef SE_EXCEPTIONS
  260.     internal_exception_handler(Class_invariant);
  261. #else
  262.     error0("Class Invariant Violation.");
  263. #endif
  264.   }
  265. }
  266.  
  267. void ac_liv(int v) {
  268.   /* Assertion Check : Loop Invariant check. */
  269.   if (!v) {
  270. #ifdef SE_EXCEPTIONS
  271.     internal_exception_handler(Loop_invariant);
  272. #else
  273.     error0("Loop Invariant Violation.");
  274. #endif
  275.   }
  276. }
  277.  
  278. int ac_lvc(int lc,int lv1,int lv2) {
  279.   /* Assertion Check : Loop Variant check. */
  280.   if (lc == 0) {
  281.     if (lv2 < 0) {
  282. #ifdef SE_EXCEPTIONS
  283.       internal_exception_handler(Loop_variant);
  284. #else
  285.       se_print_run_time_stack();
  286.       fprintf(SE_ERR,"Bad First Variant Value = %d\n",lv2);
  287.       exit(1);
  288. #endif
  289.     }
  290.     else {
  291.       return lv2;
  292.     }
  293.   }
  294.   else if ((lv2 < 0) || (lv2 >= lv1)) {
  295. #ifdef SE_EXCEPTIONS
  296.     internal_exception_handler(Loop_variant);
  297. #else
  298.     se_print_run_time_stack();
  299.     fprintf(SE_ERR,"Loop Body Count = %d (done)\n",lc);
  300.     fprintf(SE_ERR,"New Variant = %d\n",lv2);
  301.     fprintf(SE_ERR,"Previous Variant = %d\n",lv1);
  302.     exit(1);
  303. #endif
  304.   }
  305.   else {
  306.     return lv2;
  307.   }
  308. }
  309.  
  310. void ac_civ(int v) {
  311.   if (!v) {
  312. #ifdef SE_EXCEPTIONS
  313.     internal_exception_handler(Check_instruction);
  314. #else
  315.     error0("Check Assertion Violated.");
  316. #endif
  317.   }
  318. }
  319.  
  320. void se_evobt(void*o,int l,int c,int f) {
  321.   /* Error Void Or Bad Type. */
  322.   if (!o) {
  323. #ifdef SE_EXCEPTIONS
  324.     internal_exception_handler(Void_call_target);
  325. #else
  326.     error1("Target is Void.",l,c,f);
  327. #endif
  328.   }
  329.   else {
  330. #ifdef SE_EXCEPTIONS
  331.     internal_exception_handler(Void_call_target);
  332. #else
  333.     error2(o,l,c,f);
  334. #endif
  335.   }
  336. }
  337.  
  338. void sigrsp(int sig) {
  339.   printf("Received signal %d (man signal).\n",sig);
  340.   se_print_run_time_stack();
  341.   exit(1);
  342. }
  343.  
  344. void se_gc_check_id(void*o,int id) {
  345.   if (id != (((T0*)o)->id)) {
  346. #ifdef SE_EXCEPTIONS
  347.     internal_exception_handler(Routine_failure);
  348. #else
  349.     fprintf(SE_ERR,"System-validity error detected during GC cycle.\n");
  350.     fprintf(SE_ERR,"Target is not valid (not the good type).\n");
  351.     fprintf(SE_ERR,"Expected: %s, Actual: %s.\n",
  352.         s2e(t[id]),s2e(t[((T0*)o)->id]));
  353.     se_print_run_time_stack();
  354.     exit(1);
  355. #endif
  356.   }
  357. }
  358.